package com.hhsjtest.composiable.logtest

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.MotionEvent
import android.view.View

class LogView : View {
    var intercept = false

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {}
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
    }

    override fun dispatchTouchEvent(event: MotionEvent): Boolean {
        val action = event.action
        if (action == MotionEvent.ACTION_DOWN) {
            Log.e("HHSJ", "        view dispatch down")
        }
        if (action == MotionEvent.ACTION_MOVE) {
            Log.e("HHSJ", "        view dispatch move")
        }
        if (action == MotionEvent.ACTION_CANCEL) {
            Log.e("HHSJ", "        view dispatch cancel===")
        }
        if (action == MotionEvent.ACTION_UP) {
            Log.e("HHSJ", "        view dispatch up===")
        }
        return super.dispatchTouchEvent(event)
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        val action = event.action
        if (action == MotionEvent.ACTION_DOWN) {
            Log.e("HHSJ", "        view touch down 申请了处理")
            super.onTouchEvent(event)
            return true
        }
        if (action == MotionEvent.ACTION_MOVE) {
            intercept = true
            Log.e("HHSJ", "        view touch move 申请了处理")
            super.onTouchEvent(event)
//            parent?.requestDisallowInterceptTouchEvent(true)
            return true
        }
        if (action == MotionEvent.ACTION_CANCEL) {
            Log.e("HHSJ", "        view touch cancel===")
        }
        if (action == MotionEvent.ACTION_UP) {
            Log.e("HHSJ", "        view touch up===")
        }
        return super.onTouchEvent(event)
    }
}